package org.example.myleet.p786;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Solution {
    public int[] kthSmallestPrimeFraction(int[] arr, int k) {
        PriorityQueue<double[]> stack = new PriorityQueue<>(new Comparator<double[]>() {
            @Override
            public int compare(double[] o1, double[] o2) {
                if (o1[2] < o2[2]) {
                    return -1;
                } else if (o1[2] > o2[2]) {
                    return 1;
                }
                return 0;
            }
        });
        for (int i = 0; i < arr.length; ++i) {
            for (int j = arr.length - 1; j >= 0; --j) {
                if (i < j) {
                    double[] num = new double[3];
                    num[0] = arr[i];
                    num[1] = arr[j];
                    num[2] = num[0] / num[1];
                    stack.offer(num);
                }
            }
        }
        for (int i = 0; i < k - 1; ++i) {
            stack.poll();
        }
        int[] result = new int[2];
        double[] num = stack.poll();
        result[0] = (int) num[0];
        result[1] = (int) num[1];
        return result;
    }
}
